package com.mszlu.blog.admin.common;

import lombok.Data;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

@Data
public class Result<T> implements Serializable {

    private Boolean success; //true表示成功         false表示失败

    private Integer code;   //返回编码      200表示请求成功

    private String msg; //错误信息

    private T data; //数据

    private Map map = new HashMap(); //动态数据

    public Result<T> add(String key, Object value) {
        this.map.put(key, value);
        return this;
    }

    public static <T> Result<T> success(T object) {
        Result<T> r = new Result<T>();
        r.success = true;
        r.data = object;
        r.code = 200;
        return r;
    }

    public static <T> Result<T> sessionError() {
        Result<T> r = new Result<T>();
//        r.msg = msg;
        r.success = false;
        r.code = 90001;
        return r;
    }

    public static <T> Result<T> loginError() {
        Result<T> r = new Result<T>();
//        r.msg = msg;
        r.success = false;
        r.msg = "未登录或登录超时，请重新登录哦";
        r.code = 90002;
        return r;
    }
    public static <T> Result<T> loginError(String msg) {
        Result<T> r = new Result<T>();
//        r.msg = msg;
        r.success = false;
        r.msg = msg;
        r.code = 90002;
        return r;
    }


    public static <T> Result<T> potenceError() {
        Result<T> r = new Result<T>();
//        r.msg = msg;
        r.success = false;
        r.msg = "你没有权限访问哦";
        r.code = 70001;
        return r;
    }

    public static <T> Result<T> error(int code, String msg) {
        Result r = new Result();
        r.success = false;
        r.msg = msg;
        r.code = code;
        return r;
    }

    public static <T> Result<T> error(String msg) {
        Result r = new Result();
        r.success = false;
        r.msg = msg;
        r.code = 0;
        return r;
    }

    public static <T> Result<T> tokenError(String msg) {
        Result r = new Result();
        r.success = false;
        r.msg = msg;
        r.code = 90003;
        return r;
    }

    public static <T> Result<T> registerError(String msg) {
        Result r = new Result();
        r.success = false;
        r.msg = msg;
        r.code = 90004;
        return r;
    }

    public static <T> Result<T> registerError() {
        Result r = new Result();
        r.success = false;
        r.msg = "注册参数有误";
        r.code = 90004;
        return r;
    }

    public static <T> Result<T> pwdError() {
        Result r = new Result();
        r.success = false;
        r.msg = "账号密码错误";
        r.code = 90000;
        return r;
    }




}
